package com.gateio.flutter.lib_core

import androidx.annotation.Keep
import com.gateio.flutter.lib_core.model.GTFlutterEventModel

/**
 * Author: Shper
 * Created: 2023/7/7
 * Flutter 消息中心，用于接收原生端消息
 */
@Keep
object GTFlutterEventCenter {

    @JvmStatic
    @JvmOverloads
    fun <E : Enum<E>> sendMessage(action: Enum<E>, dataJson: String = "", sticky: Boolean = false) {
        GTLibCoreFlutterPlugin.sendMessage(GTFlutterEventModel(action, dataJson), sticky)
    }

    @JvmStatic
    @JvmOverloads
    fun <E : Enum<E>> sendMessage(action: Enum<E>, dataMap: Map<String, Any?>, sticky: Boolean = false) {
        GTLibCoreFlutterPlugin.sendMessage(
            GTFlutterEventModel(
                action,
                GTLibCoreFlutterPlugin.gson.toJson(dataMap)
            ), sticky
        )
    }

    @JvmStatic
    @JvmOverloads
    fun <E : Enum<E>> sendMessage(action: Enum<E>, data: Any, sticky: Boolean = false) {
        GTLibCoreFlutterPlugin.sendMessage(
            GTFlutterEventModel(
                action,
                GTLibCoreFlutterPlugin.gson.toJson(data)
            ), sticky
        )
    }

}